const { DataTypes } = require("sequelize");

const seq = require("../db/seq");

//! 创建模型 ( Model sh_user --> sh_users ) 默认会添加s
const User = seq.define(
  "sh_user",
  {
    //? id字段自增，所以会被sequelize自动维护

    user_name: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true,
      comment: "用户名, 唯一",
    },
    password: {
      type: DataTypes.CHAR(64),
      allowNull: false,
      comment: "用户密码",
    },
    phone_number: {
      type: DataTypes.CHAR(64),
      allowNull: true,
      comment: "用户绑定的手机号",
    },
    user_avatar: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "http://82.157.94.91:8000/defaultAvatar.jpg",
      comment: "用户头像地址",
    },
    user_gendar: {
      type: DataTypes.CHAR(64),
      allowNull: true,
      comment: "用户性别",
      defaultValue: "unknown",
    },
    user_signature: {
      type: DataTypes.STRING,
      allowNull: true,
      defaultValue: "我是最棒的!!!",
      comment: "用户个性签名",
    },
  },
  {
    tableName: "sh_users", //todo 直接提供表名
    //* timestamps: false,  //?让seq不会自动创建createdAt 和 updatedAt
  }
);

//!强制同步数据库(创建数据表)
/* User.sync({
  force: true, //? 将创建表, 如果表已经存在, 则将其首先删除
}); */

module.exports = User;
